<?php

namespace app\api\logic;

class CourseFile
{
    /**
     * getListByCourseId
     * @param $course_id
     * @return mixed
     */
    public function getListByCourseId($course_id)
    {
        // 查询条件
        $where = [
            'course_id' => $course_id,
            'file_status' => 1,
        ];

        // 查询字段
        $field = 'id,file_type,file_name,file_price,file_count';

        // 查询数据
        $list = app(\app\common\model\CourseFile::class)->where($where)->select();

        // 处理数据
        $dict = \app\common\model\CourseFile::DICT;
        foreach ($list as $key => $val)
        {
            $list[$key]['file_type_name'] = $dict['file_type'][$val['file_type']] ?? '-';
        }

        // 返回
        return $list ? $list->toArray() : [];
    }
}